﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyEagle : Enemy
{
    public Transform upPos, downPos;

    //private Collider2D enemyCollider;
    private Rigidbody2D rb;
    private float upLimit,downLimit;
    private bool isUp = true;
    private float speed = 4;


    protected override void Start()
    {
        base.Start();
        //enemyCollider = GetComponent<Collider2D>();
        rb = GetComponent<Rigidbody2D>();

        upLimit = upPos.position.y;
        downLimit = downPos.position.y;
    }

    void Update()
    {
        EagleMove();
    }
    void EagleMove()
    {
        if (isUp)
        {
            anim.SetBool("isDown", false);
            rb.velocity = new Vector2(rb.velocity.x, speed);
            if (rb.position.y > upLimit)    isUp = false;

        }
        else
        {
            anim.SetBool("isDown", true);
            rb.velocity = new Vector2(rb.velocity.x, -speed);
            if (rb.position.y < downLimit)    isUp = true;
        }
    }
}
